#include "MetaTable.h"

MetaClass::MetaClass( const char* cName, TypeID type ) :
	base(nullptr),
	name(cName),
	typeID(type)
{

}

MetaFunction* MetaClass::getMethod( TypeID nameID, TypeID signature, bool searchInBase/*=true */ ) const
{
	for (unsigned int i = 0; i < functions.size(); ++i)
	{
		MetaFunction* f = functions.at(i);
		if (f->nameID == nameID && f->signature == signature)
			return f;
	}

	if (searchInBase && base)
	{
		return base->getMethod(nameID, signature, searchInBase);
	}

	return nullptr;
}

bool MetaClass::isSubclass( TypeID type ) const
{
	const MetaClass* table = this;
	while (table != nullptr)
	{
		if (table->typeID == type)
			return true;
		table = table->base;
	}

	return false;
}

TypeID impl::getNextTypeID()
{
	static TypeID type= 0;
	return ++type;
}
